package com.behelpful.common.core.enums;

import com.behelpful.common.core.exceptions.ParamException;
import com.behelpful.common.core.result.ErrorResult;
import com.behelpful.common.core.utils.ExceptionUtil;
import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 授权验证方式
 *
 * @author Alay
 * @date 2021-09-24 12:45
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum AuthValidateTypeEnum implements IEnum {

    /**
     * 算数验证码
     */
    ARITHMETIC_CAPTCHA(1),
    /**
     * 中文验证码
     */
    CHINESE_CAPTCHA(2),

    /**
     * 手机验证码
     */
    PHONE_CAPTCHA(3),

    ;
    /**
     * 枚举编码
     */
    private int code;

    AuthValidateTypeEnum(int code) {
        this.code = code;
    }

    @Override
    public int getCode() {
        return code;
    }

    public static AuthValidateTypeEnum codeOf(int code) {
        AuthValidateTypeEnum[] values = AuthValidateTypeEnum.values();
        for (AuthValidateTypeEnum value : values) {
            if (value.getCode() == code) {
                return value;
            }
        }
        throw ExceptionUtil.create(ParamException.class, ErrorResult.PARAMETER_ERROR);
    }
}